<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="统一社会信用代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
              <a-input v-model="model.code" placeholder="请输入统一社会信用代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入公司名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
              <a-input v-model="model.type" placeholder="请输入公司类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司规模" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="size">
              <a-input v-model="model.size" placeholder="请输入公司规模"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="法定代表人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="legal">
              <a-input v-model="model.legal" placeholder="请输入法定代表人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="经营范围" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessScope">
              <a-input v-model="model.businessScope" placeholder="请输入经营范围"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="注册资本" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="registeredCapital">
              <a-input-number v-model="model.registeredCapital" placeholder="请输入注册资本" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成立日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="establishTime">
              <j-date placeholder="请选择成立日期" v-model="model.establishTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="营业期限" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessTerm">
              <j-date placeholder="请选择营业期限" v-model="model.businessTerm"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地址-省市区" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="addressArea">
              <a-input v-model="model.addressArea" placeholder="请输入地址-省市区"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="详情地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="addressDetails">
              <a-input v-model="model.addressDetails" placeholder="请输入详情地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="行业名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="industryName">
              <a-input v-model="model.industryName" placeholder="请输入行业名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司性质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="natureOfCompany">
              <a-input v-model="model.natureOfCompany" placeholder="请输入公司性质"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyCategory">
              <a-input v-model="model.companyCategory" placeholder="请输入公司类别"  ></a-input>
            </a-form-model-item>
          </a-col>

         
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'HteLibCompanyForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           code: [
              { required: true, message: '请输入统一社会信用代码!'},
           ],
           name: [
              { required: true, message: '请输入公司名称!'},
           ],
           type: [
              { required: true, message: '请输入公司类型!'},
           ],
           size: [
              { required: true, message: '请输入公司规模!'},
           ],
           legal: [
              { required: true, message: '请输入法定代表人!'},
           ],
           businessScope: [
              { required: true, message: '请输入经营范围!'},
           ],
           registeredCapital: [
              { required: true, message: '请输入注册资本!'},
           ],
           establishTime: [
              { required: true, message: '请输入成立日期!'},
           ],
           businessTerm: [
              { required: true, message: '请输入营业期限!'},
           ],
           addressArea: [
              { required: true, message: '请输入地址-省市区!'},
           ],
           addressDetails: [
              { required: true, message: '请输入详情地址!'},
           ],
           industryName: [
              { required: true, message: '请输入行业名称!'},
           ],
           natureOfCompany: [
              { required: true, message: '请输入公司性质!'},
           ],
           companyCategory: [
              { required: true, message: '请输入公司类别!'},
           ],
           isDel: [
              { required: true, message: '请输入删除标识!'},
           ],
        },
        url: {
          add: "/libraryCompany/hteLibCompany/add",
          edit: "/libraryCompany/hteLibCompany/edit",
          queryById: "/libraryCompany/hteLibCompany/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>